﻿Shader "Dan/2D/Snow2D"
{
    Properties
    {
        _Layer("Layer", Int) = 3
        _SnowColor ("SnowColor", Color  ) = (1,1,1,1)
        _DropDir("Drop Dir",Range(0,0.5))=0.3
        _DropSpeed("Drop Speed",Float)=2
        _SnowSize("Snow Size",Range(0,0.5))=0.1
        _Brightness("Brightness",Range(0,2))=0.8
    }
    SubShader
    {
        //Tags { "RenderType"="Transparent "  "Queue"="Transparent" "IGNOREPROJECTOR"="True"}
        Tags { "RenderType"="Transparent" "Queue"="Transparent"}
        LOD 100

        Pass
        {
           Blend One One
            
            ZWrite Off
            ZTest Always
            Cull Off
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            

            #include "UnityCG.cginc"
            #include "../ShaderLibs/UVOperator.cginc"
            #include "../ShaderLibs/Feature.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                
                return o;
            }

            float4 _SnowColor ;
            float  _DropDir;
            float _DropSpeed;
            float _SnowSize;
            float _Brightness;
            int _Layer;



            fixed4 frag (v2f i) : SV_Target
            {
                float4 snow = float4 (0,0,0,1);
                float2 uv = i.uv;
                uv *= float2(_ScreenParams.x / _ScreenParams.y, 1);
                for (int i = 0; i < _Layer; ++i)
                {
                     snow= max(snow,DrawSnow(uv,i,_DropDir,_DropSpeed,_SnowSize,_Brightness));

                }
               
              fixed4 col = _SnowColor*snow.r;
              return col;
            }
            ENDCG
        }
    }
}
